package dingyunchi.job.service.impl;

import dingyunchi.job.dao.CourseDao;
import dingyunchi.job.entity.Course;
import dingyunchi.job.service.CourseService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CourseServiceImpl implements CourseService {
    private final CourseDao courseDao;

    public CourseServiceImpl(CourseDao courseDao) {
        this.courseDao = courseDao;
    }

    @Override
    public Course save(Course course) {
        if (course.getCredit() < 1 || course.getCredit() > 5) {
            throw new IllegalArgumentException("学分应在1到5之间");
        }
        return courseDao.save(course);
    }

    @Override
    public Course findById(Long id) {
        return courseDao.findById(id);
    }

    @Override
    public List<Course> findAll() {
        return courseDao.findAll();
    }

    @Override
    public void update(Course course) {
        if (course.getCredit() < 1 || course.getCredit() > 5) {
            throw new IllegalArgumentException("学分应在1到5之间");
        }
        courseDao.update(course);
    }

    @Override
    public void delete(Long id) {
        courseDao.delete(id);
    }
}